<?php
$typeArr = Users::getArrayType();
?>

<div class="row-fluid">
    <div class="box span12">
        <div class="box-header">
            <h2><i class="icon-user"></i><span class="break"></span>
                <?php
                if ($action == 'edit')
                    echo 'Edit User: ' . $model->name;
                else
                {
                    echo 'Create ';
                    echo isset($typeArr[$type]) ? $typeArr[$type] : 'User';
                }
                ?>
            </h2>            
        </div>

        <div class="box-content">
            <div class="row-fluid">
                <?php if (Yii::app()->user->hasFlash('success')): ?>
                    <div class="alert alert-success">
                        <button type="button" class="close" data-dismiss="alert">×</button>
                        <strong>All done!</strong> <?php echo Yii::app()->user->getFlash('success'); ?>
                    </div>
                    <?php // endif; ?>
                <?php elseif (Yii::app()->user->hasFlash('error')): ?>
                    <div class="alert alert-error">
                        <button type="button" class="close" data-dismiss="alert">×</button>
                        <strong>Failed!</strong> <?php echo Yii::app()->user->getFlash('error'); ?>
                    </div>
                <?php endif; ?>


                <?php
                $form = $this->beginWidget('CActiveForm', array(
                    'id'                     => 'user-form',
//                    'enableAjaxValidation' => true,
                    'enableClientValidation' => true,
                    'htmlOptions'            => array(
                        'class'   => 'form-horizontal',
                        'enctype' => 'multipart/form-data',
                    ),
                    'focus'                  => array($model, 'username'),
                    'clientOptions'          => array(
                        'validateOnSubmit' => true,
                    ),
                ));
                ?>
                <?php echo CHtml::errorSummary($model); ?>
                <fieldset>
                    <div class="span6">
                        <div class="control-group">
                            <?php echo $form->labelEx($model, 'photo', array('class' => 'control-label')); ?>
                            <div class ="controls">
                                <div class="user_photo">
                                    <img src="<?php echo $model->publicPhoto ?>" alt="User photo">
                                </div>                                
                                <input type="file" name="file"/>
                                <?php if ($model->type == Users::TYPE_BUSINESS): ?>
                                    <br>
                                    <br>
                                    <p class="muted">Recommended resolution: 130px X 130px</p>
                                <?php endif; ?>
                            </div>
                        </div>
                        <?php if ($model->type == Users::TYPE_STAFF): ?>
                            <div class="control-group">
                                <label class="control-label" for="staff_group">Assign Label</label>
                                <div class ="controls">
                                    <?php echo CHtml::dropDownList('staff_group', $this->staff_group, Group::getAllArray()) ?>
                                </div>
                            </div>
                        <?php endif; ?>

                        <div class="control-group">
                            <?php echo $form->labelEx($model, 'email', array('class' => 'control-label')); ?>
                            <div class ="controls">
                                <?php
                                echo $form->textField($model, 'email', array(
                                    'placeholder' => $model->getAttributeLabel('email'),
                                    'class'       => 'input-file uniform_on input-reset',
                                ));
                                ?>
                                <font color="red"><?php echo $form->error($model, 'email'); ?></font>
                            </div>
                        </div>
                        <?php if ($model->type == Users::TYPE_BUSINESS): ?>
                            <div class="control-group">
                                <?php echo $form->labelEx($model, 'firstname', array('class' => 'control-label')) ?>
                                <div class ="controls">
                                    <?php
                                    echo $form->textField($model, 'firstname', array(
                                        'placeholder' => $model->getAttributeLabel('firstname'),
                                        'class'       => 'input-file uniform_on input-reset'))
                                    ?>
                                    <font color="red"> <?php echo $form->error($model, 'firstname'); ?> </font>
                                </div>
                            </div>
                            <div class="control-group">
                                <?php echo $form->labelEx($model, 'lastname', array('class' => 'control-label')) ?>
                                <div class ="controls">
                                    <?php
                                    echo $form->textField($model, 'lastname', array(
                                        'class'        => 'input-file uniform_on input-reset',
                                        'placeholder'  => $model->getAttributeLabel('lastname'),
                                        'autocomplete' => "off",
                                    ))
                                    ?>
                                    <font color="red"> <?php echo $form->error($model, 'lastname'); ?> </font>
                                </div>
                            </div>
                        <?php endif; ?>
                        <?php // if ($this->isAdmin): ?>
                        <div class="control-group">
                            <?php echo $form->labelEx($model, 'new_pass', array('class' => 'control-label')); ?>
                            <div class ="controls">
                                <?php
                                echo $form->passwordField($model, 'new_pass', array(
                                    'placeholder'  => $model->getAttributeLabel('new_pass'),
                                    'class'        => 'input-file uniform_on input-reset',
                                    'autocomplete' => "off",
                                ));
                                ?>
                                <font color="red"><?php echo $form->error($model, 'new_pass'); ?></font>
                            </div>
                        </div>
                        <div class="control-group">
                            <?php echo $form->labelEx($model, 'repassword', array('class' => 'control-label')); ?>
                            <div class ="controls">
                                <?php
                                echo $form->passwordField($model, 'repassword', array(
                                    'placeholder'  => $model->getAttributeLabel('repassword'),
                                    'class'        => 'input-file uniform_on input-reset',
                                    'autocomplete' => "off",
                                ));
                                ?>
                                <font color="red"><?php echo $form->error($model, 'repassword'); ?></font>
                            </div>
                        </div>
                        <?php // endif; ?>

                        <?php if ($action == 'edit'): ?>
                            <?php if ($model->type == Users::TYPE_STAFF AND ( $this->isAdmin OR $this->isBussiness)): ?>
                                <div class="control-group">
                                    <?php echo $form->label($model, 'password', array('class' => 'control-label')) ?>
                                    <div class ="controls">
                                        <a class="btn btn-info" href="<?php
                                        echo $this->createUrl('staff/resetPwd', array(
                                            'pk' => isset($_GET['pk']) ? $_GET['pk'] : ''
                                        ))
                                        ?>">
                                            Reset Password
                                        </a>
                                    </div>
                                </div>
                            <?php endif; ?>
                        <?php endif; ?>

                        <div class="control-group">
                            <?php echo $form->labelEx($model, 'status', array('class' => 'control-label')) ?>
                            <div class ="controls">         
                                <?php $model->status = $model->status ? $model->status : Users::STATUS_ACTIVE ?>
                                <?php
                                echo $form->radioButtonList($model, 'status', Users::getArrayStatus(), array(
                                    'template' => '<label class="radio">{input} {label}</label>'
                                ));
                                ?>
                                <font color="red"><?php echo $form->error($model, 'status'); ?></font>
                            </div>
                        </div>
                    </div>

                    <?php
                    if ($type == Users::TYPE_BUSINESS)
                    {
                        echo $this->renderPartial('//user/_form_biz', array(
                            'form'  => $form,
                            'model' => $model
                        ));
                    }
                    elseif ($type == Users::TYPE_CUSTOMER)
                    {
                        echo $this->renderPartial('//customer/_form', array(
                            'form'  => $form,
                            'model' => $model
                        ));
                    }
                    else
                    {
                        echo $this->renderPartial('//user/_form_basic', array(
                            'form'  => $form,
                            'model' => $model
                        ));
                    }
                    ?>
                    <div class="clearfix"></div>
                    <?php
                    if ($type == Users::TYPE_BUSINESS)
                    {
                        echo $this->renderPartial('//user/_upload_gallery', array(
                            'form'  => $form,
                            'model' => $model
                        ));
                    }
                    ?>
                    <hr>
                    <?php
                    echo CHtml::submitButton('Save', array('class' => 'btn btn-primary'));
                    ?>
                    <?php echo CHtml::resetButton('Reset', array('class' => 'btn', 'id' => 'btn-reset')); ?>
                </fieldset>
                <?php $this->endWidget(); ?>
            </div>
        </div>
    </div>
</div>

